<template>
  <div style="display: flex">
    <div class="trees_box">
      <el-tree
        :data="Treedata"
        accordion
        :props="defaultProps"
        highlight-current
        @node-click="handleNodeClick"
      ></el-tree>
    </div>
    <div class="app-container" style="width: 85%">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item label="试卷名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入试卷名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="试卷总分" prop="score">
          <el-input
            v-model="queryParams.score"
            placeholder="请输入试卷总分"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="所属卷库" prop="volume">
          <!-- <el-input
          v-model="queryParams.volumeLibraryName"
          placeholder="请选择所属卷库"
          clearable
          :style="{width: '100%'}"
          @focus="volume(-1)"
          ></el-input>-->
          <el-select
            v-model="queryParams.volumeLibraryId"
            placeholder="请选择所属卷库"
            clearable
            filterable
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="(item, index) in listLibraryOptions"
              :key="index"
              :label="item.name"
              :value="item.id"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="试卷分类" prop="paperType">
          <!-- <el-input
          v-model="queryParams.paperTypeName"
          placeholder="请选择试卷分类"
          clearable
          :style="{width: '100%'}"
          @focus="paperType()"
          ></el-input>-->
          <el-select
            v-model="queryParams.paperTypeId"
            placeholder="请选择试卷分类"
            clearable
            filterable
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="(item, index) in listPaper_typeoptions"
              :key="index"
              :label="item.name"
              :value="item.id"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考试时长(分钟)" prop="duration">
          <el-input
            v-model="queryParams.duration"
            placeholder="请输入考试时长(分钟)"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="试卷平均难度" prop="difficulty">
          <el-input
            v-model="queryParams.difficulty"
            placeholder="请输入试卷平均难度"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
        <!-- <el-col :span="24">
        <el-dialog width="80%" title="请选择所属卷库" :visible.sync="volumeVisible" append-to-body>
          <div class="app-container">
            <el-form
              :model="vqueryParams"
              ref="vqueryForm"
              :inline="true"
              v-show="vshowSearch"
              label-width="68px"
            >
              <el-form-item label="课程关联id" prop="classesId">
                <el-input
                  v-model="vqueryParams.classesId"
                  placeholder="请输入课程关联id"
                  clearable
                  size="small"
                  @keyup.enter.native="vhandleQuery"
                />
              </el-form-item>
              <el-form-item label="卷库名称" prop="name">
                <el-input
                  v-model="vqueryParams.name"
                  placeholder="请输入卷库名称"
                  clearable
                  size="small"
                  @keyup.enter.native="vhandleQuery"
                />
              </el-form-item>
              <el-form-item label="卷库编号" prop="code">
                <el-input
                  v-model="vqueryParams.code"
                  placeholder="请输入卷库编号"
                  clearable
                  size="small"
                  @keyup.enter.native="vhandleQuery"
                />
              </el-form-item>
              <el-form-item label="卷库状态" prop="state">
                <el-input
                  v-model="vqueryParams.state"
                  placeholder="请输入卷库状态"
                  clearable
                  size="small"
                  @keyup.enter.native="vhandleQuery"
                />
              </el-form-item>
              <el-form-item>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="vhandleQuery"
                >搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="vresetQuery">重置</el-button>
              </el-form-item>
            </el-form>

            <el-table
              v-loading="vloading"
              :data="vlibraryList"
              @row-click="vrowclick($event)"
              highlight-current-row
            >
              <el-table-column type="index" width="55" align="center" />
              <el-table-column label="卷库名称" align="center" prop="name" />
              <el-table-column label="卷库编号" align="center" prop="code" />
              <el-table-column label="卷库描述" align="center" prop="other" />
              <el-table-column label="卷库状态" align="center" prop="state" />
            </el-table>

            <pagination
              v-show="vtotal>0"
              :total="vtotal"
              :page.sync="vqueryParams.pageNum"
              :limit.sync="vqueryParams.pageSize"
              @pagination="vgetList"
            />
          </div>
           <div slot="footer" >
              <el-button @click="closeVolumeDialogF">取 消</el-button>
              <el-button type="primary" @click="closeVolumeDialogT">确 定</el-button>
            </div>
        </el-dialog>
      </el-col>
      <el-col :span="24">
        <el-dialog width="80%" title="请选择试卷分类" :visible.sync="paperVisible" append-to-body>
          <div class="app-container">
            <el-form
              :model="pqueryParams"
              ref="pqueryForm"
              :inline="true"
              v-show="pshowSearch"
              label-width="68px"
            >
              <el-form-item label="名称" prop="name">
                <el-input
                  v-model="pqueryParams.name"
                  placeholder="请输入名称"
                  clearable
                  size="small"
                  @keyup.enter.native="phandleQuery"
                />
              </el-form-item>
              <el-form-item label="其他描述" prop="other">
                <el-input
                  v-model="pqueryParams.other"
                  placeholder="请输入其他描述"
                  clearable
                  size="small"
                  @keyup.enter.native="phandleQuery"
                />
              </el-form-item>
              <el-form-item>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="phandleQuery"
                >搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="presetQuery">重置</el-button>
              </el-form-item>
            </el-form>

            <el-table
              v-loading="ploading"
              :data="ppaper_typeList"
              @row-click="prowclick($event)"
              highlight-current-row
            >
              <el-table-column type="index" width="55" align="center" />

              <el-table-column label="名称" align="center" prop="name" />
              <el-table-column label=" 创建人" align="center" prop="createBy" />
              <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="修改人" align="center" prop="updateBy" />
              <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="其他描述" align="center" prop="other" />
            </el-table>

            <pagination
              v-show="ptotal>0"
              :total="ptotal"
              :page.sync="pqueryParams.pageNum"
              :limit.sync="pqueryParams.pageSize"
              @pagination="pgetList"
            />
          </div>
                      <div slot="footer" >
              <el-button @click="closePaperDialogF">取 消</el-button>
              <el-button type="primary" @click="closePaperDialogT">确 定</el-button>
            </div>
        </el-dialog>
        </el-col>-->
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['paper:paper:add']"
            >新增</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['paper:paper:edit']"
            >修改</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['paper:paper:remove']"
            >删除</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['paper:paper:export']"
            >导出</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAddmuch"
            v-hasPermi="['paper:paper:add']"
            >批量自动组卷</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="paperList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="试卷id" align="center" prop="id" /> -->
        <el-table-column
          label="试卷名称"
          :show-overflow-tooltip="true"
          align="center"
          width="185"
          prop="name"
        />
        <el-table-column label="试卷总分" align="center" prop="score" />
        <el-table-column
          label="考试时长(分钟)"
          align="center"
          prop="duration"
        />
        <el-table-column
          label="试卷平均难度"
          align="center"
          prop="difficulty"
        />
        <el-table-column label=" 创建人" align="center" prop="createBy" />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="下载" align="center" prop="download">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-tickets"
              @click="downloadPaper(scope.row)"
              >下载试卷</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-tickets"
              @click="handleCopy(scope.row)"
              >复制</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleCheck(scope.row)"
              >预览</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <!-- 预览整张试卷 -->

      <el-dialog width="80%" title :visible.sync="paper" v-if="paper">
        <showpaper :row="paperdata"></showpaper>
      </el-dialog>
      <!-- 添加或修改试卷对话框 -->
      <el-dialog
        :title="title"
        :visible.sync="open"
        width="100%"
        v-loading="loading"
      >
        <el-row :gutter="15">
          <el-form
            ref="form"
            :model="form"
            :rules="rules"
            size="medium"
            label-width="120px"
          >
            <el-col :span="6">
              <el-form-item
                label="试卷模板"
                prop="paperTemplateId"
                v-show="shwopeperwork"
              >
                <el-select
                  v-model="form.paperTemplateId"
                  placeholder="请选择试卷模板"
                  @change="handleexammodel()"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in field105Options"
                    :key="index"
                    :label="item.name"
                    :value="item.paperTemplateId"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="试卷名称" prop="name">
                <el-input
                  v-model="form.name"
                  placeholder="请输入试卷名称"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="试卷总分" prop="score">
                <el-input
                  v-model="form.score"
                  placeholder="请选择试卷模板"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="考试时长(分钟)" prop="duration">
                <el-input
                  v-model="form.duration"
                  placeholder="请选择试卷模板"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="试卷平均难度" prop="difficulty">
                <el-input
                  v-model="form.difficulty"
                  placeholder="请选择试卷模板"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24"></el-col>
            <el-col :span="6" v-show="false">
              <el-form-item label="组卷方式" prop="field104">
                <el-select
                  v-model="form.field104"
                  placeholder="请选择组卷方式"
                  clearable
                  disabled
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in mypaperwork"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属卷库" prop="volume">
                <el-input
                  v-model="form.volumeLibraryName"
                  placeholder="请选择所属卷库"
                  clearable
                  :style="{ width: '100%' }"
                  @focus="volume(-1)"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="试卷分类" prop="paperType">
                <el-input
                  v-model="form.paperTypeName"
                  placeholder="请选择试卷分类"
                  clearable
                  :style="{ width: '100%' }"
                  @focus="paperType()"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-dialog
                width="80%"
                title="请选择所属卷库"
                :visible.sync="volumeVisible"
                append-to-body
              >
                <div class="app-container">
                  <el-form
                    :model="vqueryParams"
                    ref="vqueryForm"
                    :inline="true"
                    v-show="vshowSearch"
                    label-width="68px"
                  >
                    <el-form-item label="课程关联id" prop="classesId">
                      <el-input
                        v-model="vqueryParams.classesId"
                        placeholder="请输入课程关联id"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="卷库名称" prop="name">
                      <el-input
                        v-model="vqueryParams.name"
                        placeholder="请输入卷库名称"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="卷库编号" prop="code">
                      <el-input
                        v-model="vqueryParams.code"
                        placeholder="请输入卷库编号"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="卷库状态" prop="state">
                      <el-input
                        v-model="vqueryParams.state"
                        placeholder="请输入卷库状态"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item>
                      <el-button
                        type="primary"
                        icon="el-icon-search"
                        size="mini"
                        @click="vhandleQuery"
                        >搜索</el-button
                      >
                      <el-button
                        icon="el-icon-refresh"
                        size="mini"
                        @click="vresetQuery"
                        >重置</el-button
                      >
                    </el-form-item>
                  </el-form>

                  <el-table
                    v-loading="vloading"
                    :data="vlibraryList"
                    @row-click="vrowclick($event)"
                    highlight-current-row
                  >
                    <el-table-column type="index" width="55" align="center" />
                    <el-table-column
                      label="卷库名称"
                      align="center"
                      prop="name"
                    />
                    <el-table-column
                      label="卷库编号"
                      align="center"
                      prop="code"
                    />
                    <el-table-column
                      label="卷库描述"
                      align="center"
                      prop="other"
                    />
                    <el-table-column
                      label="卷库状态"
                      align="center"
                      prop="state"
                    />
                  </el-table>

                  <pagination
                    v-show="vtotal > 0"
                    :total="vtotal"
                    :page.sync="vqueryParams.pageNum"
                    :limit.sync="vqueryParams.pageSize"
                    @pagination="vgetList"
                  />
                  <div slot="footer">
                    <el-button @click="closeVolumeDialogF">取 消</el-button>
                    <el-button type="primary" @click="closeVolumeDialogT"
                      >确 定</el-button
                    >
                  </div>
                </div>
              </el-dialog>
            </el-col>
            <el-col :span="24">
              <el-dialog
                width="80%"
                title="请选择试卷分类"
                :visible.sync="paperVisible"
                append-to-body
              >
                <div class="app-container">
                  <el-form
                    :model="pqueryParams"
                    ref="pqueryForm"
                    :inline="true"
                    v-show="pshowSearch"
                    label-width="68px"
                  >
                    <el-form-item label="名称" prop="name">
                      <el-input
                        v-model="pqueryParams.name"
                        placeholder="请输入名称"
                        clearable
                        size="small"
                        @keyup.enter.native="phandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="其他描述" prop="other">
                      <el-input
                        v-model="pqueryParams.other"
                        placeholder="请输入其他描述"
                        clearable
                        size="small"
                        @keyup.enter.native="phandleQuery"
                      />
                    </el-form-item>
                    <el-form-item>
                      <el-button
                        type="primary"
                        icon="el-icon-search"
                        size="mini"
                        @click="phandleQuery"
                        >搜索</el-button
                      >
                      <el-button
                        icon="el-icon-refresh"
                        size="mini"
                        @click="presetQuery"
                        >重置</el-button
                      >
                    </el-form-item>
                  </el-form>

                  <el-table
                    v-loading="ploading"
                    :data="ppaper_typeList"
                    @row-click="prowclick($event)"
                    highlight-current-row
                  >
                    <el-table-column type="index" width="55" align="center" />

                    <el-table-column label="名称" align="center" prop="name" />
                    <el-table-column
                      label=" 创建人"
                      align="center"
                      prop="createBy"
                    />
                    <el-table-column
                      label="创建时间"
                      align="center"
                      prop="createTime"
                      width="180"
                    >
                      <template slot-scope="scope">
                        <span>
                          {{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}
                        </span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="修改人"
                      align="center"
                      prop="updateBy"
                    />
                    <el-table-column
                      label="修改时间"
                      align="center"
                      prop="updateTime"
                      width="180"
                    >
                      <template slot-scope="scope">
                        <span>
                          {{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}
                        </span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="其他描述"
                      align="center"
                      prop="other"
                    />
                  </el-table>

                  <pagination
                    v-show="ptotal > 0"
                    :total="ptotal"
                    :page.sync="pqueryParams.pageNum"
                    :limit.sync="pqueryParams.pageSize"
                    @pagination="pgetList"
                  />
                  <div slot="footer">
                    <el-button @click="closePaperDialogF">取 消</el-button>
                    <el-button type="primary" @click="closePaperDialogT"
                      >确 定</el-button
                    >
                  </div>
                </div>
              </el-dialog>
            </el-col>

            <el-col :span="24">
              <el-dialog
                title
                :visible.sync="outvisable"
                v-if="outvisable"
                width="80%"
                append-to-body
                center
              >
                <div v-if="judegtype">
                  <search
                    :row="{ searchitem, exitem }"
                    @componentdata="componentdata"
                  ></search>
                </div>
                <div v-if="!judegtype">
                  <showitem :row="shwo"></showitem>
                </div>
              </el-dialog>
              <el-dialog
                width="50%"
                title="小题详情"
                :visible.sync="innerVisible"
                v-if="innerVisible"
                append-to-body
              >
                <showDetail :row="propdata"></showDetail>
              </el-dialog>

              <div v-for="(item, i) in form.structureList" :key="i">
                <div class="container">
                  <span class="number" style="display: flex">
                    <span
                      style="
                        display: block;
                        width: 20%;
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                      "
                      >{{ item.name }}</span
                    >
                    <div>
                      {{ item.score }}分 共{{ item.count }}题 已选{{
                        item.templatecount
                      }}题 该大题平均难度{{ item.difficulty }}
                    </div>
                  </span>
                  <el-button
                    type="success"
                    @click="checkcontianer(i)"
                    plain
                    round
                    :disabled="item.templatecount == 0"
                    >预览大题</el-button
                  >
                  <!-- <el-button type="success" @click="checkcontianer(i)" :disabled="!(form.structureList[i].bankList!=null&&form.structureList[i].count==form.structureList[i].bankList.length)" plain round>预览大题</el-button> -->
                </div>
                <!-- 这里是选择的地方 -->
                <!-- <el-dialog width="60%" title="小题合集" @close="item.outvisable=false" :visible.sync="item.outvisable" append-to-body> -->
                <el-collapse v-model="item.quesitem" style="margin-left: 100px">
                  <el-collapse-item title="查看/隐藏小题">
                    <div>
                      <div class="questitem">
                        <div
                          class="questdetail"
                          v-for="item2 in item.count"
                          :key="item2"
                        >
                          <span
                            style="color: #e6a23c"
                            v-if="
                              item.bankList[item2 - 1] == null &&
                              item.templatedata[item2 - 1] == ''
                            "
                            >请选择小题</span
                          >
                          <span
                            style="margin-left: 10px"
                            v-if="
                              item.bankList[item2 - 1] != null ||
                              item.templatedata[item2 - 1] != ''
                            "
                            >第{{ item2 }}题</span
                          >
                          <span>
                            <el-button
                              type="primary"
                              style="margin-left: 10px; margin-right: 5px"
                              @click="handdeeletip(i, item2 - 1, item)"
                              size="mini"
                              round
                            >
                              <i class="el-icon-edit"></i>
                            </el-button>
                            <el-button
                              type="success"
                              style="margin-right: 10px"
                              @click="handAddPaper(i, item2 - 1, item)"
                              size="mini"
                              round
                            >
                              <i class="el-icon-plus"></i>
                            </el-button>
                            <el-button
                              type="success"
                              style="margin-right: 10px"
                              @click="handonecheck(i, item2 - 1, item)"
                              size="mini"
                              round
                            >
                              <i class="el-icon-view"></i>
                            </el-button>
                          </span>
                        </div>
                      </div>
                    </div>
                  </el-collapse-item>
                </el-collapse>
              </div>
            </el-col>
            <el-col :span="24">
              <el-form-item size="large" style="margin-top: 10px">
                <el-button type="primary" @click="submitForm">提交</el-button>
                <el-button @click="dialogresetForm">重置</el-button>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>

        <!-- 自动组卷选题 -->
        <el-dialog
          width="40%"
          title="自动组卷小题"
          :visible.sync="selfecontainer"
          append-to-body
        >
          <div>
            <el-form
              ref="selfeformData"
              :model="selfeformData"
              :rules="selferules"
              size="medium"
              label-width="100px"
            >
              <el-form-item label="所属章节" prop="field101">
                <el-select
                  v-model="selfeformData.field101"
                  placeholder="请选择所属章节"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in field101Options"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="一级知识点" prop="knowledgeA">
                <el-select
                  v-model="selfeformData.knowledgeA"
                  placeholder="请选择一级知识点"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in knowledgeAOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="二级知识点" prop="knowledgeB">
                <el-select
                  v-model="selfeformData.knowledgeB"
                  placeholder="请选择二级知识点"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in knowledgeBOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="考核知识点" prop="investigateKnow">
                <el-select
                  v-model="selfeformData.investigateKnow"
                  placeholder="请选择考核知识点"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in investigateKnowOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="难度" prop="categorization">
                <el-select
                  v-model="selfeformData.categorization"
                  placeholder="请选择难度"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in categorizationOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="知识分类" prop="difficulty">
                <el-select
                  v-model="selfeformData.difficulty"
                  placeholder="请选择知识分类"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in difficultyOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item size="large">
                <el-button type="primary" @click="submitselfeformData"
                  >提交</el-button
                >
                <el-button @click="selferesetForm">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-dialog>
      </el-dialog>
      <!-- 批量自动组卷 -->
      <el-dialog
        title="新增自动组卷"
        :visible.sync="Addmuch"
        width="100%"
        v-loading="loading"
      >
        <el-row :gutter="15">
          <el-form
            ref="selform"
            :model="selform"
            :rules="rules"
            size="medium"
            label-width="120px"
          >
            <!-- <el-col :span="6">
            <el-form-item label="试卷模板" prop="paperTemplateId">
              <el-select
                v-model="form.paperTemplateId"
                placeholder="请选择试卷模板"
                @change="handleexammodelself()"
                clearable
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in field104Options"
                  :key="index"
                  :label="item.name"
                  :value="item.paperTemplateId"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            </el-col>-->
            <el-col :span="6">
              <el-form-item label="试卷模板" prop="paperTemplateId">
                <el-select
                  v-model="selform.paperTemplateId"
                  placeholder="请选择试卷模板"
                  @change="handleexammodelself()"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in field104Options"
                    :key="index"
                    :label="item.autoName"
                    :value="item.id"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="试卷名称" prop="name">
                <el-input
                  v-model="selform.name"
                  placeholder="请输入试卷名称"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="4">
              <el-form-item label="试卷总分" prop="score">
                <el-input
                  v-model="selform.score"
                  placeholder="请输入试卷总分"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="考试时长(分钟)" prop="duration">
                <el-input
                  v-model="selform.duration"
                  placeholder="请选输入试卷时长"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="试卷平均难度" prop="difficulty">
                <el-input
                  v-model="selform.difficulty"
                  placeholder="请输入试卷难度"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24"></el-col>

            <!-- <el-col :span="6">
            <el-form-item label="自动组卷模板" prop="field104">
              <el-select
                v-model="form.field104"
                placeholder="请选择自动组卷模板方式"
                clearable
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in field104Options"
                  :key="index"
                  :label="item.autoName"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            </el-col>-->
            <el-col :span="6">
              <el-form-item label="试卷数量" prop="count">
                <el-input
                  v-model="selform.count"
                  placeholder="请输入试卷数量"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属卷库" prop="volume">
                <el-input
                  v-model="selform.volumeLibraryName"
                  placeholder="请选择所属卷库"
                  clearable
                  :style="{ width: '100%' }"
                  @focus="volume(-1)"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="试卷分类" prop="paperType">
                <el-input
                  v-model="selform.paperTypeName"
                  placeholder="请选择试卷分类"
                  clearable
                  :style="{ width: '100%' }"
                  @focus="paperType()"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24"></el-col>
            <!-- <el-col :span="6">
            <el-form-item label="组卷方式" prop="field104">
              <el-select
                v-model="form.field104"
                placeholder="请选择自动组卷模板方式"
                clearable
                disabled
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in field104Options"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            </el-col>-->
            <el-col :span="24">
              <el-dialog
                width="80%"
                title="请选择所属卷库"
                :visible.sync="volumeVisible"
                append-to-body
              >
                <div class="app-container">
                  <el-form
                    :model="vqueryParams"
                    ref="vqueryForm"
                    :inline="true"
                    v-show="vshowSearch"
                    label-width="68px"
                  >
                    <el-form-item label="课程关联id" prop="classesId">
                      <el-input
                        v-model="vqueryParams.classesId"
                        placeholder="请输入课程关联id"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="卷库名称" prop="name">
                      <el-input
                        v-model="vqueryParams.name"
                        placeholder="请输入卷库名称"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="卷库编号" prop="code">
                      <el-input
                        v-model="vqueryParams.code"
                        placeholder="请输入卷库编号"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="卷库状态" prop="state">
                      <el-input
                        v-model="vqueryParams.state"
                        placeholder="请输入卷库状态"
                        clearable
                        size="small"
                        @keyup.enter.native="vhandleQuery"
                      />
                    </el-form-item>
                    <el-form-item>
                      <el-button
                        type="primary"
                        icon="el-icon-search"
                        size="mini"
                        @click="vhandleQuery"
                        >搜索</el-button
                      >
                      <el-button
                        icon="el-icon-refresh"
                        size="mini"
                        @click="vresetQuery"
                        >重置</el-button
                      >
                    </el-form-item>
                  </el-form>

                  <el-table
                    v-loading="vloading"
                    :data="vlibraryList"
                    @row-click="vrowclick($event)"
                    highlight-current-row
                  >
                    <el-table-column type="index" width="55" align="center" />
                    <el-table-column
                      label="卷库名称"
                      align="center"
                      prop="name"
                    />
                    <el-table-column
                      label="卷库编号"
                      align="center"
                      prop="code"
                    />
                    <el-table-column
                      label="卷库描述"
                      align="center"
                      prop="other"
                    />
                    <el-table-column
                      label="卷库状态"
                      align="center"
                      prop="state"
                    />
                  </el-table>

                  <pagination
                    v-show="vtotal > 0"
                    :total="vtotal"
                    :page.sync="vqueryParams.pageNum"
                    :limit.sync="vqueryParams.pageSize"
                    @pagination="vgetList"
                  />
                  <div slot="footer">
                    <el-button @click="closeVolumeDialogF">取 消</el-button>
                    <el-button type="primary" @click="closeVolumeDialogT"
                      >确 定</el-button
                    >
                  </div>
                </div>
              </el-dialog>
            </el-col>
            <el-col :span="24">
              <el-dialog
                width="80%"
                title="请选择试卷分类"
                :visible.sync="paperVisible"
                append-to-body
              >
                <div class="app-container">
                  <el-form
                    :model="pqueryParams"
                    ref="pqueryForm"
                    :inline="true"
                    v-show="pshowSearch"
                    label-width="68px"
                  >
                    <el-form-item label="名称" prop="name">
                      <el-input
                        v-model="pqueryParams.name"
                        placeholder="请输入名称"
                        clearable
                        size="small"
                        @keyup.enter.native="phandleQuery"
                      />
                    </el-form-item>
                    <el-form-item label="其他描述" prop="other">
                      <el-input
                        v-model="pqueryParams.other"
                        placeholder="请输入其他描述"
                        clearable
                        size="small"
                        @keyup.enter.native="phandleQuery"
                      />
                    </el-form-item>
                    <el-form-item>
                      <el-button
                        type="primary"
                        icon="el-icon-search"
                        size="mini"
                        @click="phandleQuery"
                        >搜索</el-button
                      >
                      <el-button
                        icon="el-icon-refresh"
                        size="mini"
                        @click="presetQuery"
                        >重置</el-button
                      >
                    </el-form-item>
                  </el-form>

                  <el-table
                    v-loading="ploading"
                    :data="ppaper_typeList"
                    @row-click="prowclick($event)"
                    highlight-current-row
                  >
                    <el-table-column type="index" width="55" align="center" />

                    <el-table-column label="名称" align="center" prop="name" />
                    <el-table-column
                      label=" 创建人"
                      align="center"
                      prop="createBy"
                    />
                    <el-table-column
                      label="创建时间"
                      align="center"
                      prop="createTime"
                      width="180"
                    >
                      <template slot-scope="scope">
                        <span>
                          {{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}
                        </span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="修改人"
                      align="center"
                      prop="updateBy"
                    />
                    <el-table-column
                      label="修改时间"
                      align="center"
                      prop="updateTime"
                      width="180"
                    >
                      <template slot-scope="scope">
                        <span>
                          {{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}
                        </span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="其他描述"
                      align="center"
                      prop="other"
                    />
                  </el-table>

                  <pagination
                    v-show="ptotal > 0"
                    :total="ptotal"
                    :page.sync="pqueryParams.pageNum"
                    :limit.sync="pqueryParams.pageSize"
                    @pagination="pgetList"
                  />
                  <div slot="footer">
                    <el-button @click="closePaperDialogF">取 消</el-button>
                    <el-button type="primary" @click="closePaperDialogT"
                      >确 定</el-button
                    >
                  </div>
                </div>
              </el-dialog>
            </el-col>
            <!-- 显示内容 -->
            <el-col :span="24">
              <div v-for="(item, i) in temselfw.structureList" :key="i">
                <div class="container">
                  <span class="number"
                    >{{ item.name }} {{ item.score }}分 共{{
                      item.count
                    }}题</span
                  >
                </div>
                <div class="topic">
                  <el-table
                    :data="item.structureList"
                    style="width: 90%; margin-left: 100px"
                  >
                    <!--                  <el-table-column type="index" label="顺序" :index="indexMethod" width="180"></el-table-column>-->
                    <el-table-column
                      prop="chapterId"
                      label="所属章节"
                      width="180"
                    ></el-table-column>
                    <el-table-column
                      prop="knowledgeA"
                      label="一级知识点"
                      width="180"
                    ></el-table-column>
                    <el-table-column
                      prop="knowledgeB"
                      label="二级知识点"
                    ></el-table-column>
                    <el-table-column
                      prop="investigateKnow"
                      label="考察知识点"
                    ></el-table-column>
                    <el-table-column
                      prop="difficulty"
                      label="难度"
                    ></el-table-column>
                    <el-table-column
                      prop="categorization"
                      label="知识分类"
                    ></el-table-column>
                  </el-table>
                </div>
              </div>
            </el-col>
            <el-col :span="24">
              <el-form-item size="large" style="margin-top: 10px">
                <el-button type="primary" @click="autosubmitForm"
                  >提交</el-button
                >
                <el-button @click="dialogresetForm">重置</el-button>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </el-dialog>

      <!-- 添加题型 -->
      <el-dialog
        title="添加小题"
        :visible.sync="onselectOpen"
        width="70%"
        append-to-body
      >
        <!--      @后面的接受子组件的参数 :后面的传递参数-->
        <OneSelect
          @submitOneselect="submitOneselect"
          @getFormData="getFormData"
          :type="papeTypeStr"
        ></OneSelect>
        <!--      <BigQuestionAdd></BigQuestionAdd>-->
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  listPaper,
  copyPaper,
  getPaper,
  delPaper,
  addPaper,
  updatePaper,
  exportPaper,
  autoComposePaper,
  getQueryTree,
  downloadPaperByPaper,
} from "@/api/paper/paper";
import { listLibrary } from "@/api/paper/library";
import {
  listTemplate,
  getTemplate,
  delTemplate,
  addTemplate,
  updateTemplate,
  exportTemplate,
} from "@/api/paper/template";
import { listautoPaper, getautoPaperdetail } from "@/api/paper/Automatic";
import showDetail from "@/components/showDetail";
import search from "./search.vue";
import showitem from "./showitem.vue";
import showpaper from "./showpaper.vue";
import { listTemplate as qlistTemplate } from "@/api/topic/template";
import { listQuestionbank } from "@/api/topic/questionbank";

//单选
import SingleChoiceAdd from "@/views/topic/add/singleChoiceAdd.vue";
//多选
import MultipleChoiceAdd from "@/views/topic/add/multipleChoiceAdd.vue";
//判断
import JudgeAdd from "@/views/topic/add/judgeAdd.vue";
//填空
import CompletionAdd from "@/views/topic/add/completionAdd.vue";
//简答
import ShortAnswerAdd from "@/views/topic/add/shortAnswerAdd.vue";
//大题
import BigQuestionAdd from "@/views/topic/add/bigQuestionAdd.vue";

import OneSelect from "@/components/paperType/oneselect.vue";
import { volume } from "@/assets/mixins/volume";
import { paperType } from "@/assets/mixins/paperType";
import { listPaper_type } from "@/api/paper/paper_type";
import { downLoadZip } from "@/utils/zipdownload";

export default {
  name: "Paper",
  components: {
    showDetail: showDetail,
    search,
    showitem,
    showpaper,
    OneSelect,
    SingleChoiceAdd,
    JudgeAdd,
    MultipleChoiceAdd,
    CompletionAdd,
    ShortAnswerAdd,
    BigQuestionAdd,
  },
  mixins: [volume, paperType],
  data() {
    return {
      // 树数据
      Treedata: [],
      defaultProps: {
        children: "data",
        label: "courseName",
      },
      // 隐藏试卷模板
      shwopeperwork: false,
      //是否显示已选小题
      quesitem: false,
      onselectOpen: false,
      papeTypeStr: "",
      //小题合集的dialog
      outvisable: false,
      //内部的dialog
      innerVisible: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 试卷表格数据
      paperList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示试卷预览
      paper: false,
      //试卷预览的数据
      paperdata: [],
      //传递到详情的数据
      propdata: [],
      //自动组卷内的参数列表
      peperdatble: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        score: null,
        duration: null,
        difficulty: null,
      },
      //判断是大题预览还是小题预览
      judegtype: "",
      // structureList
      structureListI: "",
      //中间变量
      templateindex: "",
      //搜索小题
      searchitem: "",
      //已存在的小题
      exitem: [],
      //预览题目
      shwo: "",
      //自动组卷选择题目
      selfecontainer: false,
      //批量自动组卷
      Addmuch: false,
      // 临时保存自动组卷模板
      temselfw: [],
      //小题信息
      smollt: [],
      //试卷模板
      field103Options: [],
      //自动组卷表单参数
      selform: {
        name: undefined,
        duration: undefined,
        score: undefined,
        paperTemplateId: undefined,
        field107: undefined,
        field104: undefined,
        difficulty: undefined,
        structureList: [],
        volumeLibraryName: undefined,
        // 所属题库id
        volumeLibraryId: undefined,
        // 所属试卷分类id
        paperTypeId: undefined,
        paperTypeName: undefined,
      },
      // 表单参数
      form: {
        name: undefined,
        duration: undefined,
        score: undefined,
        paperTemplateId: undefined,
        field107: undefined,
        field104: undefined,
        difficulty: undefined,
        structureList: [],
        volumeLibraryName: undefined,
        // 所属题库id
        volumeLibraryId: undefined,
        // 所属试卷分类id
        paperTypeId: undefined,
        paperTypeName: undefined,
      },

      //自动组卷的数据
      selfeformData: {
        field101: undefined,
        knowledgeA: undefined,
        knowledgeB: undefined,
        investigateKnow: undefined,
        categorization: undefined,
        difficulty: undefined,
      },
      selferules: {
        field101: [
          {
            required: true,
            message: "请选择所属章节",
            trigger: "change",
          },
        ],
        knowledgeA: [
          {
            required: true,
            message: "请选择一级知识点",
            trigger: "change",
          },
        ],
        knowledgeB: [
          {
            required: true,
            message: "请选择二级知识点",
            trigger: "change",
          },
        ],
        investigateKnow: [
          {
            required: true,
            message: "请选择考核知识点",
            trigger: "change",
          },
        ],
        categorization: [
          {
            required: true,
            message: "请选择难度",
            trigger: "change",
          },
        ],
        difficulty: [
          {
            required: true,
            message: "请选择知识分类",
            trigger: "change",
          },
        ],
      },
      field101Options: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      knowledgeAOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      knowledgeBOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      investigateKnowOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      categorizationOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      difficultyOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      //所属卷库
      listLibraryOptions: [],
      //所属试卷分类
      listPaper_typeoptions: [],
      //临时保存点击的位置
      temposition: "",
      // 表单校验
      rules: {
        paperTemplateId: [
          {
            required: true,
            message: "请选择试卷模板",
            trigger: "change",
          },
        ],
        // volume: [
        //   {
        //     required: true,
        //     message: "请选择所属卷库",
        //     trigger: "change",
        //   },
        // ],
        // paperType: [
        //   {
        //     required: true,
        //     message: "请选择试卷分类",
        //     trigger: "change",
        //   },
        // ],
        name: [
          {
            required: true,
            message: "请输入试卷名称",
            trigger: "blur",
          },
        ],
        score: [
          {
            required: true,
            message: "请输入试卷总分",
            trigger: "blur",
          },
        ],
        duration: [
          {
            required: true,
            message: "请输入考试时长(分钟)",
            trigger: "blur",
          },
        ],
        paperTemplateId: [
          {
            required: true,
            message: "请选择试卷模板",
            trigger: "blur",
          },
        ],
        count: [
          {
            required: true,
            message: "请输入试卷数量",
            trigger: "blur",
          },
        ],
        difficulty: [
          {
            required: true,
            message: "请输入试卷平均难度",
            trigger: "blur",
          },
        ],
      },
      field105Options: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      mypaperwork: [
        {
          label: "手动组卷",
          value: 1,
        },
        {
          label: "自动组卷",
          value: 2,
        },
      ],
      field104Options: [
        {
          label: "手动组卷",
          value: 1,
        },
        {
          label: "自动组卷",
          value: 2,
        },
      ],
    };
  },
  created() {
    this.getList();
    this.getQueryTree();
    this.listautoPaper();
    this.getlistLibrary();
  },
  methods: {
    //获取卷库,试卷分类
    getlistLibrary() {
      listLibrary().then((response) => {
        this.listLibraryOptions = response.rows;
      });
      listPaper_type().then((response) => {
        this.listPaper_typeoptions = response.rows;
      });
    },

    getQueryTree() {
      this.loading = true;
      getQueryTree().then((res) => {
        this.Treedata = res;
        for (let i = 0; i < this.Treedata.length; i++) {
          if (this.Treedata[i].data != null) {
            for (let j = 0; j < this.Treedata[i].data.length; j++) {
              this.Treedata[i].data[j].data = [];
            }
          }
        }
        console.log(this.Treedata, "树");
        this.loading = false;
      });
    },

    // 树形目录点击后获取对应的学生信息
    handleNodeClick(data) {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        name: null,
        score: null,
        duration: null,
        difficulty: null,
      };
      //cccfffhhh
      // debugger;
      switch (data.flag) {
        case "startingUnit": // 一级
          break;
        case "course": // 二级
          // this.queryParams.courseId = data.treeData[0].id;
          break;
        case "bankType": // 三级
          this.queryParams.id = data.id;
          break;
        default:
          break;
      }
      /** 查询课程信息列表 */
      this.getList();
    },

    // 批量自动组卷提交
    autosubmitForm() {
      if (this.selform.volume == "") {
        return this.$message.error("请选择所属卷库");
      } else if (this.selform.paperType == "") {
        return this.$message.error("请选择试卷分类");
      }
      this.selform.duration = parseFloat(this.selform.duration);
      this.selform.count = parseFloat(this.selform.count);
      this.selform.tempflag = 1;
      this.$refs["selform"].validate((valid) => {
        if (valid) {
          this.loading = true;
          if (this.selform.id != null) {
            updatePaper(this.selform).then((response) => {
              this.msgSuccess("修改成功");
              // this.loading=false
              this.Addmuch = false;
              this.getList();
              this.reset();
            });
          } else {
            console.log(this.selform);
            autoComposePaper(this.selform).then((response) => {
              this.msgSuccess("新增成功");
              // this.loading=false
              this.Addmuch = false;
              this.getList();
              this.reset();
            });
          }
          this.loading = true;
        }
      });
    },
    //获取自动组卷模板
    listautoPaper() {
      listautoPaper().then((response) => {
        this.field104Options = response.rows;
      });
    },
    submitOneselect(val) {
      //你在添加试卷拿到组件填的值
      console.log(val);
    },
    handleAddmuch() {
      this.Addmuch = true;
      this.resetselft();
    },
    //自动组卷提交
    submitselfeformData() {
      this.$refs["selfeformData"].validate((valid) => {
        if (valid) {
          this.form.structureList[this.temposition].templatedata[
            this.templateindex
          ] = this.selfeformData;
          console.log("提交之后", this.form.structureList[this.temposition]);
          this.selfecontainer = false;
        }
        // TODO 提交表单
      });
    },
    selferesetForm() {
      this.selfeformData = {
        field101: undefined,
        knowledgeA: undefined,
        knowledgeB: undefined,
        investigateKnow: undefined,
        categorization: undefined,
        difficulty: undefined,
      };
    },
    //联级选择器
    cascader() {
      console.log("联级", this.cascaderselectedOptions3);
    },

    //表单重置
    dialogresetForm() {
      (this.form = {
        name: undefined,
        duration: undefined,
        score: undefined,
        paperTemplateId: undefined,
        field107: undefined,
        difficulty: undefined,
        volumeLibraryName: undefined,
        // 所属题库id
        volumeLibraryId: undefined,
        // 所属试卷分类id
        paperTypeId: undefined,
        paperTypeName: undefined,
      }),
        (this.selform = {
          name: undefined,
          duration: undefined,
          score: undefined,
          paperTemplateId: undefined,
          field107: undefined,
          difficulty: undefined,
          volumeLibraryName: undefined,
          // 所属题库id
          volumeLibraryId: undefined,
          // 所属试卷分类id
          paperTypeId: undefined,
          paperTypeName: undefined,
        });
    },
    ////点击小题后添加,接受子组件传值
    componentdata(componentdata) {
      this.form.structureList[this.structureListI].bankList[
        this.templateindex
      ] = componentdata;
      this.form.structureList[this.structureListI].bankList[
        this.templateindex
      ].paperOrdered = this.templateindex;
      //计算难度
      let sum = 0;
      for (
        let i = 0;
        i < this.form.structureList[this.structureListI].bankList.length;
        i++
      ) {
        if (
          this.form.structureList[this.structureListI].bankList[i] != undefined
        ) {
          sum +=
            this.form.structureList[this.structureListI].bankList[i].difficulty;
        }
      }
      this.form.structureList[this.structureListI].difficulty = parseFloat(
        sum / this.form.structureList[this.structureListI].bankList.length
      ).toFixed(1);
      var sumtotal = parseFloat(0);
      for (let j = 0; j < this.form.structureList.length; j++) {
        sumtotal += parseFloat(this.form.structureList[j].difficulty);
      }

      this.form.difficulty = parseFloat(
        parseFloat(sumtotal).toFixed(1) / this.form.structureList.length
      ).toFixed(1);

      this.form.structureList[this.structureListI].templatecount =
        this.form.structureList[this.structureListI].bankList.length;
      this.$message({
        message: "添加成功",
        type: "success",
      });
      this.outvisable = false;
    },
    /** 查询试卷列表 */
    getList() {
      this.loading = true;
      listPaper(this.queryParams).then((response) => {
        this.paperList = response.rows;
        console.log("paperList: ", this.paperList);
        this.total = response.total;
        this.loading = false;
      });
      listTemplate().then((response) => {
        this.field105Options = response.rows;
        for (let i = 0; i < this.field105Options.length; i++) {
          this.field105Options[i].paperTemplateId = this.field105Options[i].id;
          this.field105Options[i].id = null;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //自动组卷表单重置
    resetselft() {
      this.form = {
        id: null,
        classesId: null,
        createBy: null,
        createduration: null,
        updateBy: null,
        updateduration: null,
        field104: 2,
        name: null,
        score: null,
        structureList: [],
        duration: null,
        difficulty: null,
        volumeLibraryName: null,
        // 所属题库id
        volumeLibraryId: null,
        // 所属试卷分类id
        paperTypeId: null,
        paperTypeName: null,
      };
      this.resetForm("form");
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        classesId: null,
        createBy: null,
        createduration: null,
        updateBy: null,
        updateduration: null,
        field104: 1,
        name: null,
        score: null,
        duration: null,
        difficulty: null,
        volumeLibraryName: null,
        // 所属题库id
        volumeLibraryId: null,
        // 所属试卷分类id
        paperTypeId: null,
        paperTypeName: null,
      };
      this.resetForm("form");
    },
    //自动组卷选择了试卷模板
    handleexammodelself() {
      getautoPaperdetail(this.selform.paperTemplateId).then((response) => {
        this.temselfw = response;
        this.selform.structureList = this.temselfw.structureList;
        this.selform.score = response.autoScore;
        this.selform.difficulty = response.autoDifficulty;
        this.selform.autoQuestionId = response.autoQuestionId;
      });
      //  getTemplate(this.form.paperTemplateId).then((response) => {
      //   this.form = response.data;
      //   //设置组卷方式为手动组卷
      //   // this.form.field104=2;
      //   this.form.duration = this.form.time;
      //   this.form.paperTemplateId = response.data.id;
      //   this.form.id = null;
      //   for (let i = 0; i < this.form.structureList.length; i++) {
      //     this.form.structureList[i].outvisable = false;
      //     this.form.structureList[i].quesitem = 1;
      //     this.form.structureList[i].templatedata = [];
      //     for (let j = 0; j < this.form.structureList[i].count; j++) {
      //       this.form.structureList[i].templatedata[j] = [];
      //     }
      //     this.form.structureList[i].difficulty = 0;
      //     this.form.structureList[i].score = parseFloat(
      //       this.form.structureList[i].score
      //     );
      //     this.form.structureList[i].templatecount = 0;
      //     this.form.structureList[i].bankList = [];
      //   }
      // });
    },
    //手动组卷选择了试卷模板
    handleexammodel() {
      getTemplate(this.form.paperTemplateId).then((response) => {
        this.form = response.data;
        //设置组卷方式为手动组卷
        this.form.field104 = 1;
        this.form.duration = this.form.time;
        this.form.paperTemplateId = response.data.id;
        this.form.id = null;
        for (let i = 0; i < this.form.structureList.length; i++) {
          this.form.structureList[i].outvisable = false;
          this.form.structureList[i].quesitem = 1;
          this.form.structureList[i].templatedata = [];
          for (let j = 0; j < this.form.structureList[i].count; j++) {
            this.form.structureList[i].templatedata[j] = [];
          }
          this.form.structureList[i].difficulty = 0;
          this.form.structureList[i].score = parseFloat(
            this.form.structureList[i].score
          );
          this.form.structureList[i].templatecount = 0;
          this.form.structureList[i].bankList = [];
        }
      });
    },

    //预览小题详细
    handonecheck(findex, sindex, item) {
      if (this.form.structureList[findex].bankList[sindex] == null) {
        this.$confirm("请先选择小题", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.handdeeletip(findex, sindex, item);
          })
          .catch(() => {});
      } else {
        this.propdata = this.form.structureList[findex].bankList[sindex];
        this.innerVisible = true;
      }
    },
    //预览一道大题内部的所有小题
    checkcontianer(item) {
      if (this.form.structureList[item].bankList == null) {
        this.$message({
          message: "请先选择小题",
          type: "warning",
        });
      } else {
        this.outvisable = true;
        this.judegtype = false;
        this.shwo = this.form.structureList[item];
      }
    },
    //添加试卷时候点击修改小题后
    handdeeletip(index, temindex, templaitem) {
      // if (this.form.field104 == 1) {
      this.judegtype = true;
      this.searchitem = templaitem;
      this.exitem = this.form.structureList[index].bankList;
      const data = {
        beanName: this.form.structureList[index].beanName,
        questionTemplateId: this.form.structureList[index].questionTemplateId,
      };
      this.structureListI = index;
      listQuestionbank(data).then((response) => {
        console.log("demo");
        this.smollt = response.rows;
      });
      this.outvisable = true;
      this.templateindex = temindex;
      // } else {
      //   this.temposition = index;
      //   this.selfecontainer = true;
      //   this.templateindex = temindex;
      //   this.selferesetForm();
      // }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.shwopeperwork = true;
      this.title = "添加试卷";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.shwopeperwork = false;
      const ids = row.id || this.ids;
      getPaper(ids).then((response) => {
        this.form = response.data;
        for (let i = 0; i < this.form.structureList.length; i++) {
          if (this.form.structureList[i].bankList == []) {
            this.form.structureList[i].templatecount = 0;
          } else {
            this.form.structureList[i].templatecount =
              this.form.structureList[i].bankList.length;
            let sum = 0;
            for (
              let j = 0;
              j < this.form.structureList[i].bankList.length;
              j++
            ) {
              sum += this.form.structureList[i].bankList[j].difficulty;
            }
            this.form.structureList[i].difficulty = parseFloat(
              sum / this.form.structureList[i].bankList.length
            ).toFixed(1);
          }
        }
        this.form.field104 == 1;
        console.log("修改时的数据", this.form);
        this.open = true;
        this.title = "修改试卷";
      });
    },
    //预览整张试卷
    handleCheck(row) {
      this.paper = true;
      const ids = row.id || this.ids;
      this.paperdata = {
        id: ids,
      };

      // getPaper(ids).then((response) => {
      //   this.paperdata=response.data
      //   console.log("试卷111",this.paperdata)
      // });
    },
    //下载试卷
    downloadPaper(row) {
      this.$confirm("试卷是否包含答案", "下载试卷提示", {
        cancelButtonText: "不包含",
        confirmButtonText: "包含",
        type: "warning",
        callback: (action) => {
          let flag = false;
          if (action === "confirm") {
            flag = true;
          }
          downLoadZip(
            `/paper/paper/downloadPaperByPaper/${row.id}/${flag}`,
            `${row.name}`,
            "pdf"
          );
        },
      }).catch((error) => {
        console.log(error);
      });
    },
    //复制整张试卷
    handleCopy(row) {
      let data = {
        paperId: row.id,
      };
      copyPaper(data).then((response) => {
        if (response.code === 200) {
          this.$message({
            message: "复制成功",
            type: "success",
          });
        } else {
          this.$message.error("复制失败");
        }
      });
      this.getList();
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.loading = true;
          if (this.form.id != null) {
            updatePaper(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.loading = false;
              this.open = false;
              this.getList();
              this.reset();
            });
          } else {
            addPaper(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.loading = false;
              this.open = false;
              this.getList();
              this.reset();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除试卷编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delPaper(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有试卷数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportPaper(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    //  添加题目
    handAddPaper(findex, sindex, item) {
      this.onselectOpen = true;
      this.structureListI = findex;
      this.templateindex = sindex;
      //单选
      console.log("beanname ", item.beanName);
      this.papeTypeStr = item.beanName;
    },
    getFormData(val) {
      this.componentdata(val);
      this.onselectOpen = false;
    },
  },
};
</script>
<style scoped>
.questitem {
  display: flex;
  flex-flow: wrap;
  margin-bottom: 20px;
  margin-left: 10px;
  background-color: #ebeef5;
}

.questdetail {
  margin-top: 5px;
  margin-bottom: 5px;
  margin-left: 10px;
  height: 48px;
  padding-left: 5px;
  line-height: 48px;
  /* width: 15%; */
  border-radius: 30px;
  background-color: #fff;
  border: 1px solid #e4e7ed;
}

.questdetail1 {
  margin-top: 5px;
  margin-bottom: 5px;
  margin-left: 10px;
  height: 48px;
  padding-left: 5px;
  line-height: 48px;
  width: 13%;
  border-radius: 30px;
  background-color: #fff;
  border: 1px solid #e4e7ed;
}

.number {
  display: block;
  height: 36px;
  margin-right: 20px;
  width: 400px;
  color: #303133;
  line-height: 36px;
  text-align: center;
  border: 1px solid #67c23a;
  padding-left: 15px;
}

.container {
  display: flex;
  margin-left: 100px;
  margin-bottom: 10px;
  margin-top: 10px;
}

.topic {
  font-size: 20px;
  font-weight: 600;
  width: 100%;
  border-bottom: 2px solid #dcdfe6;
}
</style>
